import sys
from pathlib import Path
# 将项目根目录添加到 sys.path
sys.path.append(str(Path(__file__).parent.parent))
from PyQt5.QtWidgets import QApplication
from core.serial_driver import SerialDriver
from core.protocol import SimpleTextProtocol
from core.data_processor import DataProcessor
from ui.main_window import MainWindow

def main():
    app = QApplication(sys.argv)
    serial_driver = SerialDriver()
    protocol_parser = SimpleTextProtocol()
    # protocol_parser = ModbusProtocol()
    data_processor = DataProcessor(protocol_parser)
    window = MainWindow(serial_driver, data_processor)
    window.refresh_ports()
    window.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()